"""
---------------------------------------------------------------------
- File: roles.py
- Date: 2025/11/5
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 系统角色相关的schema
---------------------------------------------------------------------
"""
from typing import List

from pydantic import ConfigDict
from sqlmodel import SQLModel, Field

from app.schemas.enums import RoleStatusEnum
from app.schemas.sqlmode_base import IdTimeModel


class RoleBase(SQLModel):
    """
    角色基础模型
    """

    model_config = ConfigDict(from_attributes=True)
    role_no: str | None = Field(None, description="角色编号")
    role_name: str | None = Field(None, description="角色名称")
    role_desc: str | None = Field(None, description="角色描述")
    status: RoleStatusEnum | None = Field(None, description="状态")


class RoleCreate(RoleBase):
    """
    创建角色模型
    """

    pass


class RoleUpdate(RoleBase):
    """
    更新角色模型
    """

    pass


class RoleRead(IdTimeModel, RoleBase):
    """
    角色详情模型
    """

    pass


class RoleReadList(SQLModel):
    """
    角色详情列表模型
    """

    list: List[RoleRead] = Field(default_factory=list, description="数据列表")
    total: int = Field(default=0, description="总数", alias="total")


class UserInfo(SQLModel):
    id: int | None = Field(None, description="用户ID")
    user_name: str | None = Field(None, description="用户名")


class RoleWithUser(RoleRead):
    """
    角色详情（含用户）模型
    """

    users: list[UserInfo] = Field(default_factory=list, description="用户信息")
